package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsOrderGoodsMapper;
import com.qf.mapper.DtsOrderMapper;
import com.qf.pojo.DtsBrand;
import com.qf.pojo.DtsOrder;
import com.qf.pojo.DtsOrderGoods;
import com.qf.pojo.DtsRole;
import com.qf.vo.DayStatis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;

@Service
public class DtsOrderServiceImpl implements DtsOrderService {
    @Autowired
    private DtsOrderMapper dtsOrderMapper;
    @Autowired
    private DtsOrderGoodsMapper dtsOrderGoodsMapper;


//    @Autowired
//    private StatMapper statMapper;

    @Override
    public int count() {

        Integer count = dtsOrderMapper.selectCount(null);
        return count;
    }

    @Override
    public List<DayStatis> findOrderDayStatis(int statisDaysRang) {
        return dtsOrderMapper.findOrderDayStatis(statisDaysRang);
    }

    @Override
    public IPage<DtsOrder> selectPage(int page, int limit, String sort, String order, Integer userId, String orderSn ,int[] orderStatusArray) {
        QueryWrapper<DtsOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(!StringUtils.isEmpty(userId),"user_id",userId);
        queryWrapper.eq(!StringUtils.isEmpty(orderSn),"order_sn",orderSn);
        queryWrapper.in(!StringUtils.isEmpty(orderStatusArray),"order_status",orderStatusArray);

        queryWrapper.orderBy(!StringUtils.isEmpty(sort),"asc".equalsIgnoreCase(order),sort);

        return dtsOrderMapper.selectPage(new Page<DtsOrder>(page,limit),queryWrapper);
    }
//快递公司
    @Override
    public List<Map<String, Object>> options() {
        QueryWrapper<DtsRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id value ,name label").eq("deleted",false);//启用
        return null;
    }

    @Override
    public DtsOrderGoods findorderGoods(int id) {
        return dtsOrderGoodsMapper.selectOne(new QueryWrapper<DtsOrderGoods>().eq("order_id",id));
    }

    @Override
    public DtsOrder findorder(int id) {
        return dtsOrderMapper.selectOne(new QueryWrapper<DtsOrder>().eq("id",id));
    }
}
